/*
 * @Descripttion: 
 * @Author: zhangchong zc16607@gmail.com
 * @Date: 2023-03-02 18:42:43
 * @LastEditors: zhangchong zc16607@gmail.com
 * @LastEditTime: 2023-03-03 11:42:48
 */
const commonRes = require('../utils/commonRes')
const { getKey, setKey } = require('../utils/fileDb')
const { sm4Encrypt } = require('../utils/index')

class Account {

  static async ntlist(req, res) {
    let data = getKey('nastool')
    commonRes(res, data)
  }

  static async ntadd(req, res) {
    let data = req.body
    if (!data.account) return commonRes(res, null, { message: '账号不能为空', status: 'error' })
    setKey('nastool', { ...data, password: sm4Encrypt(data.password) })
    commonRes(res, null, { message: '添加成功' })
  }

  static async ntdel(req, res) {
    setKey('nastool', { "account": "", "password": "" })
    commonRes(res, null, { message: '删除成功' })
  }
}

module.exports = Account